﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

public partial class Common_DefaultImg : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            if (FileUp1.FileName != "")
            {
                string[] FileName = FileUp1.FileName.Split('.');
                if (FileName[1] == "jpg" || FileName[1] == "JPG")
                {
                    string path = MapPath("~/UploadFile/DefaultImg/1.jpg");
                    FileUp1.SaveAs(path);
                }
            }
            if (FileUp2.FileName != "")
            {
                string[] FileName = FileUp2.FileName.Split('.');
                if (FileName[1] == "jpg" || FileName[1] == "JPG")
                {
                    string path = MapPath("~/UploadFile/DefaultImg/2.jpg");
                    FileUp2.SaveAs(path);
                }
            }
            //if (FileUp3.FileName != "")
            //{
            //    string[] FileName = FileUp3.FileName.Split('.');
            //    if (FileName[1] == "jpg" || FileName[1] == "JPG")
            //    {
            //        string path = MapPath("~/UploadFile/DefaultImg/3.jpg");
            //        FileUp3.SaveAs(path);
            //    }
            //}
            ClientScript.RegisterStartupScript(GetType(), "Msg", "alert('替换成功')", true);
        }
        catch
        {
            ClientScript.RegisterStartupScript(GetType(), "Msg", "alert('替换失败')", true);
        }

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        string path = MapPath("~/UploadFile/DefaultImg/3.jpg");
        FileInfo fn = new System.IO.FileInfo(path);

        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.ContentType = "application/octet-stream";
        HttpContext.Current.Response.ClearHeaders();
        HttpContext.Current.Response.ClearContent();
        HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + fn.Name);
        HttpContext.Current.Response.WriteFile(fn.FullName);
        HttpContext.Current.Response.End();
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        string path = MapPath("~/UploadFile/DefaultImg/1.jpg");

        FileInfo fn = new System.IO.FileInfo(path);

        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.ContentType = "application/octet-stream";
        HttpContext.Current.Response.ClearHeaders();
        HttpContext.Current.Response.ClearContent();
        HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + fn.Name);
        HttpContext.Current.Response.WriteFile(fn.FullName);
        HttpContext.Current.Response.End();
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        string path = MapPath("~/UploadFile/DefaultImg/2.jpg");

        FileInfo fn = new System.IO.FileInfo(path);

        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.ContentType = "application/octet-stream";
        HttpContext.Current.Response.ClearHeaders();
        HttpContext.Current.Response.ClearContent();
        HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + fn.Name);
        HttpContext.Current.Response.WriteFile(fn.FullName);
        HttpContext.Current.Response.End();
    }
}
